Skip to content

proxy: add DNS pre-resolution for provider endpoints - #55

Open
BenediktChlopik wants to merge 4 commits into
kaiser-data:mainfrom
BenediktChlopik:dns-pre-resolution
Open

BenediktChlopik wants to merge 4 commits into
kaiser-data:mainfrom
BenediktChlopik:dns-pre-resolution

Conversation

@BenediktChlopik

Copy link
Copy Markdown
Contributor

On config load/reload, asynchronously pre-resolve DNS for all enabled provider BaseURLs so the first request doesn't pay a cold DNS lookup. Failures are logged but don't block the proxy.

~10–50 ms saved on first request per provider

On config load/reload, asynchronously pre-resolve DNS for all enabled
provider BaseURLs so the first request doesn't pay a cold DNS lookup.
Failures are logged but don't block the proxy.
@BenediktChlopik
BenediktChlopik marked this pull request as draft November 22, 2026 12:18
@kaiser-data

Copy link
Copy Markdown
Owner

Thanks for this, Benedikt! Warming DNS on load/reload fits the project's focus on speed, and running it in the background so it never blocks startup is the right design.

One blocker before I can look closer:

  1. The diff removes about 500 lines of pkg/proxy/server.go. That includes Start, handleChatCompletions, serveDirectModel, writeTimeout and UpdateCatalog, which is why CI fails. It looks like the file was overwritten during a rebase or merge with an older copy. Could you rebase on current main (which includes perf: route requests ~24× faster on ARM (no per-request regex or catalog copies) #42–fix(proxy): load config and filters as one snapshot per request #46) so the diff shows only the DNS change?

Once it's rebased, two small questions:

  1. Go's resolver doesn't cache by default, so the warm-up only helps if the OS resolver caches (systemd-resolved, mDNSResponder). On a bare Linux box or a container without a caching resolver, the first request still does a lookup. Could you mention that, or measure the before/after on one machine, so we can describe the gain honestly in the README?
  2. A short test that a reload with a bad hostname only logs and doesn't block would be nice.

Thanks again, looking forward to the rebased version!

The goroutine spawned by UpdateConfig was reading cfg.Providers while
the caller could mutate it after UpdateConfig returned (as done in
TestDirectModel_UsesBuildBody). Snapshot the DNS hosts before spawning
the goroutine so the lookup runs on a detached copy.
@BenediktChlopik
BenediktChlopik marked this pull request as ready for review November 30, 2026 11:04
Bene added 2 commits November 30, 2026 12:07
Verifies that UpdateConfig with an unresolvable provider hostname:
- Returns without error (does not block on DNS)
- Logs the failure asynchronously
- Leaves the server functional for subsequent requests
@BenediktChlopik

BenediktChlopik commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

For the 500-line change, I tried using GitHub Copilot to fix the data race, but it didn’t help. free-llm-proxy-router’s coding strategy does a better job :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants